"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.importCss = exports.importJs = exports.readVideo = exports.readImg = void 0;
function readImg(url) {
    return new Promise((r) => {
        const img = new Image();
        img.src = url;
        img.onload = function () {
            r({ img, w: img.width, h: img.height });
        };
    });
}
exports.readImg = readImg;
function readVideo(url) {
    return new Promise((r) => {
        const video = document.createElement('video');
        video.onloadedmetadata = () => {
            r({ video, w: video.videoWidth, h: video.videoHeight });
        };
        video.src = url;
        video.load();
    });
}
exports.readVideo = readVideo;
function importJs(src, key) {
    const hash = btoa(key || src);
    if (document.querySelector(`[data-hash='${hash}']`))
        return Promise.resolve();
    return new Promise((r, j) => {
        const el = document.createElement('script');
        el.src = src;
        el.dataset.hash = hash;
        el.onload = r;
        el.onerror = j;
        document.head.appendChild(el);
    });
}
exports.importJs = importJs;
function importCss(src, key) {
    const hash = btoa(key || src);
    if (document.querySelector(`[data-hash='${hash}']`))
        return Promise.resolve();
    return new Promise((r, j) => {
        const el = document.createElement('link');
        el.rel = 'stylesheet';
        el.href = src;
        el.dataset.hash = hash;
        el.onload = r;
        el.onerror = j;
        document.head.appendChild(el);
    });
}
exports.importCss = importCss;
